package com.xiaohei.rabbitmq.seven;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.xiaohei.rabbitmq.utils.RabbitmqUtils;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: 王希辰
 * @Date: 2022/3/18 11:32
 */
public class EmitLogTopic {
    public static final String EXCHANGE_NAME="topic_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitmqUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        Map<String,String> bindingKeyMap = new HashMap<>();
        bindingKeyMap.put("quick.orange.rabbit","Q1Q2");
        bindingKeyMap.put("lazy.orange.elephant","Q1Q2");
        bindingKeyMap.put("quick.orange.fox","Q1");
        bindingKeyMap.put("lazy.brown,fox","Q2");
        bindingKeyMap.put("lazy.pink.rabbit","Q2");
        bindingKeyMap.put("quick.brown.fox","丢弃");
        bindingKeyMap.put("quick.orange.male.rabbit","丢弃");
        bindingKeyMap.put("lazy.orange.male.rabbit","Q2");
        for (Map.Entry<String, String> bindingEntry : bindingKeyMap.entrySet()) {
            String routingKey= bindingEntry.getKey();
            String message=bindingEntry.getValue();

            channel.basicPublish(EXCHANGE_NAME,routingKey,null,message.getBytes(StandardCharsets.UTF_8));
            System.out.println("生产者发出消息:"+message);
        }

    }
}
